# Copyright (c) 2018 Presto Labs Pte. Ltd.
# Author: leon

from coin.exchange.base.kr_rest.currency import NativeCurrency
from coin.exchange.bittrex_v1.constants import currency_list


def to_native_currency(currency_str):
  assert currency_str in currency_list, currency_str
  return currency_str


def from_native_currency(native_currency_str):
  currency_str = native_currency_str.upper()
  assert currency_str in currency_list, native_currency_str
  return currency_str


class BittrexCurrency(NativeCurrency):
  _exchange = "Bittrex"

  def __init__(self, currency_str):
    try:
      super().__init__(currency_str, to_native_currency(currency_str))
      return
    except AssertionError:
      pass

    try:
      super().__init__(from_native_currency(currency_str), currency_str)
      return
    except AssertionError:
      raise

  @classmethod
  def FromCurrency(cls, currency):
    return BittrexCurrency(currency.currency)

  @classmethod
  def FromStrCurrencyImpl(cls, currency_str, current_datetime):
    return BittrexCurrency(currency_str)

  @classmethod
  def FromStrNativeCurrencyImpl(cls, native_currency_str, current_datetime):
    return BittrexCurrency(native_currency_str)
